package com.shop.dao.impl;

import com.shop.dao.IItemDao;
import com.shop.entity.Item;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ItemDaoImpl extends BaseDao implements IItemDao {

    private static Map<String,String> map = new HashMap<>();

    static {
        map.put("i_id","iid");
        map.put("o_id","oid");
        map.put("p_id","pid");
        map.put("i_count","icount");
        map.put("i_num","inum");
    }

    /**
     * 插入订单项
     * @param item
     * @return
     */
    @Override
    public int insert(Item item) {
        String sql = "insert into item values(null,?,?,?,?)";
        return update(sql,item.getOid(),item.getPid(),item.getIcount(),item.getInum());
    }

    /**
     * 根据订单id查询所有订单项
     * @param oid
     * @return
     */
    @Override
    public List<Item> findItemByOid(String oid) {
        String sql = "select i_id,o_id,p_id,i_count,i_num from item where o_id = ?";
        return queryForList(Item.class,sql,map,oid);
    }


}
